﻿package mortal.game.view.copy.groupCopy.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.groupCopy.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GroupCopyPasswordWin extends SmallWindow
    {
        private var _passWord:GTextInput;
        private var _btnOk:GButton;
        private var _btnCancel:GButton;
        private var _tcopy:TCopy;
        private var _sgroup:SCopyWaitingGroup;
        private static var _instance:GroupCopyPasswordWin;

        public function GroupCopyPasswordWin(param1:ILayer = null)
        {
            if (_instance != null)
            {
                throw new Error(" GroupCopyPasswordWin 单例 ");
            }
            this.setSize(215, 125);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            paddingBottom = 30;
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35236), 17, 57, 80, 20, this));
            this._passWord = UIFactory.gTextInput(87, 57, 120, 22, this);
            this._passWord.textField.wordWrap = true;
            this._passWord.maxChars = 8;
            this._passWord.restrict = "0-9a-zA-Z";
            this._passWord.textField.filters = [FilterConst.glowFilter];
            this._btnOk = UIFactory.gButton(Language.getString(35237), 40, 103, 60, 25, this);
            this._btnOk.configEventListener(MouseEvent.CLICK, this.setGroupCopy);
            this._btnCancel = UIFactory.gButton(Language.getString(35238), 126, 103, 60, 25, this);
            this._btnCancel.configEventListener(MouseEvent.CLICK, this.cancel);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._passWord.dispose(param1);
            this._passWord = null;
            this._btnOk.dispose(param1);
            this._btnOk = null;
            this._btnCancel.dispose(param1);
            this._btnCancel = null;
            return;
        }// end function

        private function setGroupCopy(event:MouseEvent) : void
        {
            var _loc_3:GroupCopyLeaveOperData = null;
            var _loc_4:Array = null;
            var _loc_2:* = new SGroupOper();
            _loc_2.fromEntityId = Cache.instance.role.entityInfo.entityId;
            _loc_2.toEntityId = this._sgroup.captainId;
            _loc_2.fromPlayer = new SPublicPlayer();
            _loc_2.fromPlayer.entityId = Cache.instance.role.entityInfo.entityId;
            _loc_2.type = EGroupOperType._EGroupOperTypeApply;
            _loc_2.copyCode = this._tcopy.code;
            _loc_2.fromPlayer.guildId = new SEntityId();
            _loc_2.fromPlayer.copyId = new SEntityId();
            _loc_2.copyCode = this._tcopy.code;
            _loc_2.password = this._passWord.text;
            if (Cache.instance.group.isInGroup)
            {
                _loc_3 = new GroupCopyLeaveOperData(GroupCopyLeaveOperData.Apply);
                _loc_3.tcopy = this._tcopy;
                _loc_3.sgroupOper = _loc_2;
                Dispatcher.dispatchEvent(new DataEvent(EventName.GroupLeave, _loc_3));
            }
            else
            {
                _loc_4 = new Array();
                _loc_4.push(_loc_2);
                Dispatcher.dispatchEvent(new DataEvent(EventName.GroupInviteOper, _loc_4));
            }
            return;
        }// end function

        private function cancel(event:MouseEvent) : void
        {
            this.hide();
            return;
        }// end function

        public function set data(param1:Object) : void
        {
            this._sgroup = param1.sgroup;
            this._tcopy = param1.tcopy;
            return;
        }// end function

        public static function get instance() : GroupCopyPasswordWin
        {
            if (_instance == null)
            {
                _instance = new GroupCopyPasswordWin;
            }
            return _instance;
        }// end function

        public static function get isViweShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
